package com.ssh.dao.impl;

import com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException;
import com.ssh.dao.BaseDao;
import com.ssh.dao.EmployeeDao;
import com.ssh.domain.Employee;
import org.hibernate.Session;
import org.hibernate.query.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by H-209-FX-XY on 2018/4/12.
 */
@Repository
public class EmployeeDaoImpl extends BaseDao implements EmployeeDao{

    @Override
    public Employee findByUsernameAndPassword(Employee employee) {
        System.out.println("findByUsernameAndPassword ... " + employee.getUsername()+ "..." + employee.getPassword());
        return null;
    }

    @Override
    public void save(Employee employee) {
        hibernateTemplate.save(employee);
    }

    @Override
    public void updateByUsername(Employee employee) {
        hibernateTemplate.update(employee);
    }

    @Override
    public void deleteByUsername(Employee employee) {
        hibernateTemplate.delete(employee);
    }

    @Override
    public List<Employee> findByUsername(Employee employee) {
        String sql = "from Employee where username = ?";
        List<Employee> list = (List<Employee>) hibernateTemplate.find(sql,employee.getUsername());
        return list;
    }
}
